import MySQLdb
class DbHelper():
    def __init__(self):
        self.con=DbHelper.__createCon()
        self.cur=self.con.cursor()
    @staticmethod
    def __createCon():
        con=MySQLdb.connect(
            host="localhost",
            port=3306,
            user="root",
            passwd="123456",
            db="recs"
        )
        return  con
    def save(self,sql,datas):
        self.cur.executemany(sql,datas)
        self.con.commit()
    def query(self,sql):
        self.cur.execute(sql)
        rs=self.cur.fetchall()
        return rs
if __name__ == '__main__':
    helper=DbHelper()
    rs=helper.query("select title from books where id<5")
    print(rs)
